const { Sequelize, DataTypes } = require('sequelize')
const fs = require('fs')
const user = require('./User')
let sequelize = new Sequelize('softdb', 'postgres', 'zheng54088.', {
    host: 'nbyydss.top',
    dialect: 'postgres'
})

let file = fs.readdirSync(__dirname)
let files = file.filter(item => {
    return item.endsWith('.js') && item != 'index.js'
})

let resObj = {}
files.filter(item => {
    let modelName = item.replace('.js', '')
    let tabName = modelName.toLowerCase()
    let temObj = require(__dirname + '/' + item)
    resObj[modelName] = sequelize.define(tabName, temObj)
})

console.log(resObj);
resObj.sync = async () => {
    sequelize.sync({ force: true }).then(data => {
        resObj.User.bulkCreate([
            {
                biaoti: 'sdf',
                zhaiyao: 'asdfs',
                neirong: 'ggg',
                fenlei: 'ss',
                zuozhe: 'aa'
            },
            {
                biaoti: 'sss',
                zhaiyao: 'ddd',
                neirong: 'ggg',
                fenlei: 'ss',
                zuozhe: 'aa'
            },
            {
                biaoti: 'www',
                zhaiyao: 'aaa',
                neirong: 'ccc',
                fenlei: 'ss',
                zuozhe: 'aa'
            },
        ])
    })
}
module.exports = resObj
// let User=sequelize.define('User',{
//     name:{
//         type:DataTypes.STRING
//     },
//     age:{
//         type:DataTypes.STRING
//     }
// })

// User.sync({force:true})